package Card.view;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

/*
 * Set the background of UI to the picture we use.
 * @author Juthamas Uthamaphethai 5510546964
 * @author Natcha Chidchob 5510546026
 */
public class ImagePanel extends JPanel {
	/** The background image. */
	private Image img;

	/*
	 * The constructor.
	 * 
	 * @param img String name of image.
	 */
	public ImagePanel(String img) {
		this(new ImageIcon(img).getImage());
	}

	/*
	 * The constructor.
	 * 
	 * @param img the image.
	 */
	public ImagePanel(Image img) {
		this.img = img;
		Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
		setPreferredSize(size);
		setMinimumSize(size);
		setMaximumSize(size);
		setSize(size);
		setLayout(null);
	}

	/*
	 * paint component.
	 * 
	 * @param g of Graphics
	 */
	public void paintComponent(Graphics g) {
		g.drawImage(img, 0, 0, null);
	}
}
